//package com.cn.hadoop;
//
//import org.apache.hadoop.conf.Configuration;
//import org.apache.hadoop.fs.*;
//import org.apache.hadoop.io.IOUtils;
//import org.junit.After;
//import org.junit.Before;
//import org.junit.Test;
//
//import java.io.*;
//import java.net.URISyntaxException;
//import java.util.Arrays;
//
//public class DdfsTest {
//    Configuration conf;
//    FileSystem fs;
//
//    @Before
//    public void befor() throws IOException, URISyntaxException, InterruptedException {
//        conf = new Configuration(true);
//        conf.addResource("hdfs-site.xml");
//        conf.addResource("core-site.xml");
////        conf = new Configuration();
////        conf.set("fs.defaultFS", "mycluster");
////        conf.set("dfs.nameservices", "mycluster");
////        conf.set("dfs.ha.namenodes." + "mycluster", "nn1,nn2");
////        conf.set("dfs.namenode.rpc-address." + "mycluster" + ".nn1", "172.16.50.24:8020");
////        conf.set("dfs.namenode.rpc-address." + "mycluster" + ".nn2", "172.16.50.21:8020");
////        //conf.setBoolean(name, value);
////        conf.set("dfs.client.failover.proxy.provider." + "mycluster",
////                "org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider");
////        conf.set("fs.defaultFS", "hdfs://node2:9000");
////        conf.set("fs.defaultFS","hdfs://node2");
////        fs = FileSystem.get(new URI("hdfs://node2:9000"), conf, "root");
//        fs = FileSystem.get(conf);
//    }
//
//    @After
//    public void after() throws IOException {
//        fs.close();
//    }
//
//    @Test
//    public void test() throws IOException {
//        Path path = new Path("/user");
////        fs.create(path);
//        System.out.println(fs.getHomeDirectory());
//        System.out.println(fs.getScheme());
//        System.out.println(fs.exists(path));
////        System.out.println(fs.getChildFileSystems());
//        System.out.println(fs.getStatus());
////        System.out.println(conf.get("fs.defaultFS"));
//    }
//
//    @Test
//    public void upload() throws IOException {
//        Path path = new Path("/user/text.txt");
//        FSDataOutputStream fsDataOutputStream = fs.create(path);
//        FileInputStream fileInputStream = new FileInputStream(new File("C:\\Users\\yihanyuan\\hadooptest1.txt"));
//        IOUtils.copyBytes(new BufferedInputStream(fileInputStream), fsDataOutputStream, conf, true);
//    }
//
//    @Test
//    public void download() throws IOException {
////        Path path = new Path("/user/text.txt");
//        Path path = new Path("/user/hadooptest.txt");
//        FSDataInputStream fsInputStream = fs.open(path);
//        System.out.println(fs.getStatus(path));
//        System.out.println(fsInputStream.getFileDescriptor());
////        System.out.println((char) fsInputStream.read());
////        System.out.println((char) fsInputStream.readByte());
////        System.out.println((char) fsInputStream.readByte());
////        System.out.println((char) fsInputStream.readByte());
////        System.out.println((char) fsInputStream.readByte());
////        System.out.println((char) fsInputStream.readByte());
////        System.out.println((char) fsInputStream.readByte());
////        System.out.println((char) fsInputStream.readByte());
////        System.out.println((char) fsInputStream.readByte());
////        System.out.println((char) fsInputStream.readByte());
////        System.out.println((char) fsInputStream.readByte());
////        System.out.println((char) fsInputStream.readByte());
////        System.out.println((char) fsInputStream.readByte());
////        System.out.println((char) fsInputStream.readByte());
////        System.out.println((char) fsInputStream.readByte());
//        FileOutputStream fileOutputStream = new FileOutputStream("C:\\Users\\yihanyuan\\hadoopdownoad1.txt");
//        byte[] bytes = new byte[1024 * 1024];
//        int length = 0;
//        while ((length = fsInputStream.read(bytes)) > 0) {
//            fileOutputStream.write(bytes, 0, length);
//        }
//        fileOutputStream.close();
//    }
//
//    @Test
//    public void block() throws IOException {
//        Path path = new Path("/user/text.txt");
//        FileStatus fileStatus = fs.getFileStatus(path);
//        BlockLocation[] fileBlockLocations = fs.getFileBlockLocations(fileStatus, 0, fileStatus.getLen());
//        Arrays.asList(fileBlockLocations).stream().forEach(System.out::println);
//    }
//}
